/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package crm.salesOrderProcessing.session;

import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import crm.salesOrderProcessing.entity.ProductEntity;
import javax.persistence.Query;

@Stateless
@LocalBean
public class ProductManageSessionBean {

    @PersistenceContext(unitName = "MerlionFoodERP-ejbPU")
    private EntityManager em;
    private ProductEntity product;

    public void saveNewProduct(List<String> productNameList,  List<Double>  basicPriceList,  List<Double> promotionPriceList) {
        product=new ProductEntity();
    
        product.setProductName(productNameList.get(0));
        product.setBasePrice(basicPriceList.get(0));
        product.setPromotionPrice(promotionPriceList.get(0));
        em.persist(product);
        
        product=new ProductEntity();
        
        product.setProductName(productNameList.get(1));
        product.setBasePrice(basicPriceList.get(1));
        product.setPromotionPrice(promotionPriceList.get(1));
        em.persist(product);
        
         product=new ProductEntity();
         
        product.setProductName(productNameList.get(2));
        product.setBasePrice(basicPriceList.get(2));
        product.setPromotionPrice(promotionPriceList.get(2));
        em.persist(product);
        
         product=new ProductEntity();
        
        product.setProductName(productNameList.get(3));
        product.setBasePrice(basicPriceList.get(3));
        product.setPromotionPrice(promotionPriceList.get(3));
        em.persist(product);
        
    }

    public ProductEntity getProductById(Long id) {
        return em.find(ProductEntity.class, id);
    }
     public List<String> getProductNames(){
        Query query=em.createQuery("SELECT c.productName FROM ProductEntity c");
        return query.getResultList();
    }
}
